﻿/*************************************************************************************
 * 文 件 名:   TestUI_FileLoadCtrl
 * 
 * 描    述:   IHK_FileLoadUtility工具测试代码
 * 
 * 版    本：  V1.0
 * 创 建 者：  京产肠饭
 * 创建时间：  2022/5/13
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
*************************************************************************************/

using UnityEngine;
using UnityEngine.UI;
using QFramework;
using UnityEngine.Video;
using HKTools;

public class TestUI_FileLoadCtrl : MonoBehaviour, IController
{
    public IArchitecture GetArchitecture()
    {
        return HKFileLoad_Architecture.Interface;
    }

    public Button loadImg_Btn;
    public Button loadVideo_Btn;
    public Button loadAudio_Btn;

    public Button audioPlay_Btn;

    public Image img;

    public VideoPlayer videoPlayer;

    void Start()
    {
        loadImg_Btn.onClick.AddListener(() =>
        {
            this.GetUtility<IHK_FileLoadUtility>().LoadImage(GetImgCallback);
        });

        loadVideo_Btn.onClick.AddListener(() =>
        {
            this.GetUtility<IHK_FileLoadUtility>().LoadVideo(GetVideoCallback);
        });

        loadAudio_Btn.onClick.AddListener(() =>
        {
            this.GetUtility<IHK_FileLoadUtility>().LoadAudio(GetAudioCallback);
        });

        audioPlay_Btn.onClick.AddListener(() =>
       {
           if (audioPlay_Btn.GetComponent<AudioSource>().clip != null)
               audioPlay_Btn.GetComponent<AudioSource>().Play();
       });
    }

    void GetImgCallback(Texture2D texture, string storePath)
    {
        Debug.Log(storePath);
        img.sprite = texture.ToSprite();
    }

    void GetVideoCallback(string storePath)
    {
        Debug.Log(storePath);
        videoPlayer.url = storePath;
    }

    void GetAudioCallback(AudioClip audioClip, string storePath)
    {
        audioPlay_Btn.GetComponent<AudioSource>().clip = audioClip;
        audioPlay_Btn.GetComponentInChildren<Text>().text = "已加载音频";

        Debug.Log(storePath);
    }
}
